<template>
  <view class="chat">
    <view class="header">
      <text class="title">对话</text>
      <view class="new-chat" @click="startNewChat">+</view>
    </view>
    
    <view class="content">
      <view class="chat-list">
        <view class="chat-item" v-for="chat in chatList" :key="chat.id" @click="goToChat(chat)">
          <view class="avatar">{{ chat.avatar }}</view>
          <view class="info">
            <text class="name">{{ chat.name }}</text>
            <text class="last-message">{{ chat.lastMessage }}</text>
            <text class="time">{{ chat.time }}</text>
          </view>
          <view class="status" v-if="chat.unread > 0">
            <text class="unread-count">{{ chat.unread }}</text>
          </view>
        </view>
      </view>
      
      <view class="empty-state" v-if="chatList.length === 0">
        <text class="empty-icon">💬</text>
        <text class="empty-text">还没有对话记录</text>
        <text class="empty-desc">开始你的第一个AI对话吧</text>
        <button class="btn btn-primary" @click="startNewChat">开始对话</button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      chatList: [
        {
          id: 1,
          name: '智能助手',
          avatar: '🤖',
          lastMessage: '你好！我是你的AI助手，有什么可以帮助你的吗？',
          time: '刚刚',
          unread: 0
        },
        {
          id: 2,
          name: '写作助手',
          avatar: '✍️',
          lastMessage: '我已经帮你修改好了文章的开头部分...',
          time: '10分钟前',
          unread: 2
        },
        {
          id: 3,
          name: '学习导师',
          avatar: '📚',
          lastMessage: '今天的学习计划已经制定完成...',
          time: '1小时前',
          unread: 0
        }
      ]
    }
  },
  
  methods: {
    startNewChat() {
      // 跳转到聊天详情页面，开始新对话
      uni.navigateTo({
        url: '/pages/chat-detail/chat-detail?new=true'
      })
    },
    
    goToChat(chat) {
      // 跳转到聊天详情页面
      uni.navigateTo({
        url: `/pages/chat-detail/chat-detail?id=${chat.id}&name=${chat.name}`
      })
    }
  }
}
</script>

<style scoped>
.chat {
  min-height: 100vh;
  background-color: var(--primary-bg);
  padding-bottom: 50px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 16px;
  background-color: var(--secondary-bg);
  border-bottom: 1px solid var(--border-color);
}

.title {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-primary);
}

.new-chat {
  width: 40px;
  height: 40px;
  background-color: var(--accent-color);
  color: #333;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

.new-chat:active {
  background-color: #E0C090;
  transform: scale(0.95);
}

.content {
  padding: 16px;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 16px;
  background-color: var(--secondary-bg);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.chat-item:active {
  background-color: rgba(240, 217, 181, 0.1);
}

.avatar {
  width: 48px;
  height: 48px;
  background-color: rgba(240, 217, 181, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-right: 16px;
}

.info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.last-message {
  font-size: 18px;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.time {
  font-size: 16px;
  color: var(--text-muted);
}

.status {
  margin-left: 12px;
}

.unread-count {
  background-color: var(--error-color);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 84px;
  margin-bottom: 24px;
}

.empty-text {
  font-size: 24px;
  font-weight: bold;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-desc {
  font-size: 20px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.btn {
  padding: 12px 32px;
  border-radius: 8px;
  border: none;
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background-color: var(--accent-color);
  color: #333;
}

.btn-primary:active {
  background-color: #E0C090;
}
</style>
